﻿using MediatR;
using Traceability.Commont.Domains.AnimalsDomainFiles;
using Traceability.Commont.Domains.BatchManagementFiles;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;
namespace U.Enterprise.Api.Applications.WhitestripWeighing
{
    public class WhiteStripWeighingCreateHandler : IRequestHandler<WhiteStripWeighingCreateCommon, Resqults>
    {
        private readonly IBateRepository<LiveAnimalweighing> _LiveAnimalweighing;
        private readonly IBateRepository<WhiteNotes> _WhiteNote;

        public WhiteStripWeighingCreateHandler(IBateRepository<LiveAnimalweighing> liveAnimalweighing, IBateRepository<WhiteNotes> whiteNote)
        {
            _LiveAnimalweighing = liveAnimalweighing;
            _WhiteNote = whiteNote;
        }

        public async Task<Resqults> Handle(WhiteStripWeighingCreateCommon request, CancellationToken cancellationToken)
        {

            var list = new Resqults() { Code=0};


            var res = new WhiteNotes()
            {
                ShoppingDesignationid = request.ShoppingDesignationid,
                SlaughterNumber=request.SlaughterNumber,
                Stashid=request.Stashid,
                Ductionid=request.Ductionid,
                isyes=request.isyes,
                ScratchTheFat=request.ScratchTheFat,
                NetWeight =request.NetWeight,
                WhiteNoteid=request.WhiteNoteid,
                WhiteNoteNum=request.WhiteNoteNum,
                WhiteNoteRemark=request.WhiteNoteRemark,
                WhiteNoteTare=request.WhiteNoteTare,
                WhiteNoteTime=request.WhiteNoteTime,
                WhiteNoteWeight=request.WhiteNoteWeight,
            };

           var Getnum=  await _WhiteNote.Add(res);
            list.Code=Getnum;   
            //if(Getnum!=null)
            //{

            //    var HLive=_LiveAnimalweighing.GetAll().Where(x=>x.LiveAnimalweighingId ==request.WhiteWeightid).FirstOrDefault();

            //    HLive.WeightNum -= request.WhiteNoteNum;

            //   var Success=  _LiveAnimalweighing.Update(HLive);
            //    if(Success!=null)
            //    {
            //        list.Code = 1;
            //    }
            //}
            return list;




        }
    }
}
